package com.sean.controller;

import com.sean.model.Student;
import com.sean.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping(value = "/student")
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping(value = "/list")
    public List<Student> queryList(@RequestBody Student student) {
        return studentService.queryList();
    }

    @PostMapping(value = "/add")
    public Boolean add(@RequestBody Student student) {
        try {
            studentService.add(student);
            return Boolean.TRUE;
        } catch (Exception e) {
            return Boolean.FALSE;
        }
    }

    @PostMapping(value = "/update")
    public Boolean update(@RequestBody Student student) {
        try {
            studentService.update(student);
            return Boolean.TRUE;
        } catch (Exception e) {
            return Boolean.FALSE;
        }
    }

    @PostMapping(value = "/delete")
    public Boolean delete(@RequestBody Student student) {
        try {
            studentService.delete(student.getId());
            return Boolean.TRUE;
        } catch (Exception e) {
            return Boolean.FALSE;
        }
    }
}
